<?php
echo "<h3>Your cart:</h3> <br /><br />";
//print_r(Yii::app()->session['pids']);
//Yii::app()->session['pcounts']['0'] = 3;
//print_r(Yii::app()->session['pcounts']);
//print_r($_SESSION);
//print_r(isset($_SESSION));exit();
//print_r($cartItems);

$sumPrice = 0;
?>

<?php if (count($cartItems) > 0): ?>

    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'cart-form',
        'enableAjaxValidation' => false,
            ));
    ?>
    <table border="0" cellspacing="20">
        <tr>
            <th width="65%">Book</th>
            <th width="10%">Price</th>
            <th>Quantity</th>
            <th>Remove Item</th>
        </tr>
        <?php foreach ($cartItems as $key => $cartItem): ?>
            <tr>
                <td><?php echo CHtml::link($cartItem->name, array('site/book', 'id' => $cartItem->productId)); ?></td>
                <td><?php echo Helper::showPriceWithCurrency($cartItem->price); ?></td>
                <td><?php echo CHtml::textField("product" . $cartItem->productId, $cartQuantities[$key], array("width" => "10")); ?></td>
                <td><?php echo CHtml::link("Remove", array('site/removefromcart', 'remove' => $cartItem->productId), array('submit' => array('removefromcart', 'remove' => $cartItem->productId), 'confirm' => 'Are you sure you want to delete this item?')); ?></td>
            </tr>
            <?php $sumPrice += $cartItem->price * $cartQuantities[$key]; ?>
        <?php endforeach; ?>
        <tr>
            <td><b>Total</b></td>
            <td><b><?php echo Helper::showPriceWithCurrency($sumPrice); ?></b></td>
        </tr>
    </table>
    <br />
    <p align="center">
        <?php // echo CHtml::link("Update Cart", array("site/updatecart"), array("class" => "button")); ?>
        <?php echo CHtml::submitButton("Update Cart", array('class' => "button")); ?>
        <?php echo CHtml::link("Clear Cart", array("site/clearcart"), array("class" => "button")); ?>
        <?php echo CHtml::link("Checkout", array("site/checkout"), array("class" => "button")); ?>
    </p>
    <?php $this->endWidget(); ?>
<?php else: ?>
    <h5>Your shopping cart is empty</h5>
<?php endif; ?>
